/********************************************************************
Name: Table A1: Comparison of Election Sample to Universe of 
	Sheriff Elections
Author: Dan Thompson
Date: August 2019
Notes:
********************************************************************/

* Set the working directory 
gl root = "$sanctuary_root"
gl root = "YOUR_WORKING_DIRECTORY"

* Bring in the analysis dataset
use "$root/data/elections descriptive analysis data.dta", clear

* Focus on the places where we should see elections
keep if expected==1

* Make the state partisan control data long
foreach v in governor_dem house_dem_share senate_dem_share {
	gen `v' = .
	replace `v' = `v'2015 if year==2016
	forval y=2000/2015{
		replace `v' = `v'`y' if year==`y'
		drop `v'`y'
	}
}

* Row 1
sum region_midwest
sum region_midwest if gathered==1
sum region_midwest if large_partisan==1
sum region_midwest if large_partisan_gathered==1

* Row 2
sum region_northeast
sum region_northeast if gathered==1
sum region_northeast if large_partisan==1
sum region_northeast if large_partisan_gathered==1

* Row 3
sum region_south
sum region_south if gathered==1
sum region_south if large_partisan==1
sum region_south if large_partisan_gathered==1

* Row 4
sum region_west
sum region_west if gathered==1
sum region_west if large_partisan==1
sum region_west if large_partisan_gathered==1

* Row 5
sum dist
sum dist if gathered==1
sum dist if large_partisan==1
sum dist if large_partisan_gathered==1

* Row 6
sum pop2000
sum pop2000 if gathered==1
sum pop2000 if large_partisan==1
sum pop2000 if large_partisan_gathered==1

* Row 7
sum foreign
sum foreign if gathered==1
sum foreign if large_partisan==1
sum foreign if large_partisan_gathered==1

* Row 8
sum pres_dem
sum pres_dem if gathered==1
sum pres_dem if large_partisan==1
sum pres_dem if large_partisan_gathered==1

* Row 9
sum governor_dem
sum governor_dem if gathered==1
sum governor_dem if large_partisan==1
sum governor_dem if large_partisan_gathered==1

* Rows 10 and 11
unique state county
unique state county if gathered==1
unique state county if large_partisan==1
unique state county if large_partisan_gathered==1

